package com.skycode7.servlet;

import com.skycode7.bean.NoticeBean;
import com.skycode7.dao.NoticeDao;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.util.Date;

@WebServlet("/noticeEdit.jsp")
public class NoticeEditServlet extends HttpServlet {
    @Override
    protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
            throws javax.servlet.ServletException, java.io.IOException {
        req.setCharacterEncoding("UTF-8");
        String noticeID = req.getParameter("noticeID");
        String title = req.getParameter("title");
        String content = req.getParameter("content");
        NoticeBean noticeBean = new NoticeBean();
        noticeBean.setNoticeID(Integer.parseInt(noticeID));
        noticeBean.setNoticeTitle(title);
        noticeBean.setNoticeContent(content);
        noticeBean.setNoticeTime((new Date()).toString());
        noticeBean.setAdminName("admin");
        int result = (new NoticeDao()).updateNotice(noticeBean);
        if (result > 0) {
            resp.sendRedirect("noticeList.html");
        } else {
            req.getRequestDispatcher("noticeEdit.jsp").forward(req, resp);
        }
    }
}
